from pyglet import input

#Gamepad - provides an interface for gamepad/joystick buttons
#TODO - allow scenes to customize properties reading the input values
class Gamepad(object):
	def __init__(self):
		js = input.get_joysticks()
		if js:
			self.js = js[0]
			self.js.open()
		else:
			self.js = None
	
	@property
	def b1(self):
		if not self.js: return 0
		return self.js.buttons[0]
	@property
	def b2(self):
		if not self.js: return 0
		return self.js.buttons[1]
	@property
	def b3(self):
		if not self.js: return 0
		return self.js.buttons[2]
	@property
	def b4(self):
		if not self.js: return 0
		return self.js.buttons[3]
	@property
	def b5(self):
		if not self.js: return 0
		#return self.js.buttons[4]
	@property
	def b6(self):
		if not self.js: return 0
		#return self.js.buttons[5]
	@property
	def b7(self):
		if not self.js: return 0
		#return self.js.buttons[6]
	@property
	def b8(self):
		if not self.js: return 0
		return self.js.buttons[7]
	@property
	def l(self):
		if not self.js: return 0
		#return self.js.buttons[4]
	@property
	def r(self):
		if not self.js: return 0
		#return self.js.buttons[5]
	@property
	def up(self):
		if not self.js: return 0
		return self.js.hat_y == 1
	@property
	def down(self):
		if not self.js: return 0
		return self.js.hat_y == -1
	@property
	def left(self):
		if not self.js: return 0
		return self.js.hat_x == -1
	@property
	def right(self):
		if not self.js: return 0
		return self.js.hat_x == 1
	
	@property
	def analog1x(self):
		if not self.js: return 0
		return self.js.x
	@property
	def analog1y(self):
		if not self.js: return 0
		return self.js.y